home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
55375
/
55375.xpi
/
chrome
/
chromeFiles
/
content
/
btUtilities.js
< prev
next >
Wrap
Text File
|
2009-11-15
|
40KB
|
1,026 lines
/* This filech contains helper functions */
/* It has to be included AFTER btClient.js */
BrandThunder.initialize = function(brandObject) {
var AMO = false;
var includeBing = false;
var prefbranch=Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch);
var btPrefBranch = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefService)
.getBranch("extensions.brandthunder.");
if (!brandObject.utilities) {
brandObject.utilities = {};
}
function log(string) {
var aConsoleService = Components.classes["@mozilla.org/consoleservice;1"]
.getService(Components.interfaces.nsIConsoleService);
aConsoleService.logStringMessage(string);
}
/* This function uses the presence of a rebranding extension to indicate */
/* That this is a full build, not just the extension/theme */
function isFullBuild() {
return false;
}
function openLink(brandObject, event, url) {
if (typeof(url) == "undefined") {
url = brandObject.urls[event.target.id];
}
if (brandObject.redirect && !url.match("redirect.php") && !url.match("faq.php") && !url.match("firstrun.php") && !url.match("getsatisfaction.com")) {
url = brandObject.redirect + "?url=" + url;
}
if (url.match("redirect.php")) {
url += "&client=" + brandObject.releaseIdentifier;
//var curLang = "en";
//try {
// curLang = Components.classes["@mozilla.org/preferences-service;1"]
// .getService(Components.interfaces.nsIPrefService)
// .getBranch(null)
// .getCharPref("general.useragent.locale")
// .substr(0,2);
//}
//catch (e) {}
//if (curLang != "en") {
// url += "&lang=" + curLang;
//}
}
// openUILink(url, event);
var tab = getBrowser().addTab(url);
getBrowser().selectedTab = tab;
return;
}
function restartApp() {
// Notify all windows that an application quit has been requested.
var os = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);
var cancelQuit = Components.classes["@mozilla.org/supports-PRBool;1"]
.createInstance(Components.interfaces.nsISupportsPRBool);
os.notifyObservers(cancelQuit, "quit-application-requested", "restart");
// Something aborted the quit process.
if (cancelQuit.data)
return;
var nsIAppStartup = Components.classes["@mozilla.org/toolkit/app-startup;1"]
.getService(Components.interfaces.nsIAppStartup);
nsIAppStartup.quit(nsIAppStartup.eRestart | nsIAppStartup.eAttemptQuit);
}
/* This function generates a release identifier of the form: */
/* 001-Brand# (to be assigned per brand as they come in) */
/* X = Type of release (x = xpi, e = exe, d = dmg, file extension) */
/* 001- Release Version (just incremented by 1 for each release for the brand) */
/* US - country (US, CA, etc) */
function getReleaseIdentifier(brandObject) {
var releaseIdentifier = brandObject.clientCode;
var rdfs = Components.classes["@mozilla.org/rdf/rdf-service;1"]
.getService(Components.interfaces.nsIRDFService);
var extensionDS= Components.classes["@mozilla.org/extensions/manager;1"]
.getService(Components.interfaces.nsIExtensionManager).datasource;
var extension = rdfs.GetResource("urn:mozilla:item:" + brandObject.extensionID);
var arc = rdfs.GetResource("http://www.mozilla.org/2004/em-rdf#updateURL");
var updateURL = extensionDS.GetTarget(extension, arc, true); if (updateURL) {
releaseIdentifier += "X";
} else {
releaseIdentifier += "A";
}
releaseIdentifier += brandObject.clientVersion;
releaseIdentifier += brandObject.clientCountry;
return releaseIdentifier;
}
function addToPermissionManager(domain) {
var ioService = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService);
var pm = Components.classes["@mozilla.org/permissionmanager;1"]
.getService(Components.interfaces.nsIPermissionManager);
var uri = ioService.newURI("http://" + domain, null, null);
pm.add(uri, "popup", 1);
pm.add(uri, "install", 1);
}
function addAsk(brandObject, replace) {
var searchSvc = Components.classes["@mozilla.org/browser/search-service;1"]
.getService(Components.interfaces.nsIBrowserSearchService);
var oldPosition;
var oldEngine;
if (replace) {
var visibleEngines = searchSvc.getVisibleEngines({});
for (let i=0; i < visibleEngines.length; i++) {
if (visibleEngines[i].name == "Ask") {
oldPosition = i;
oldEngine = visibleEngines[i];
break;
}
}
if (oldEngine) {
searchSvc.removeEngine(oldEngine);
}
}
searchSvc.addEngineWithDetails("Ask", "data:image/x-icon;base64,AAABAAEAEBAAAAEACABoBQAAFgAAACgAAAAQAAAAIAAAAAEACAAAAAAAQAEAAAAAAAAAAAAAAAEAAAAAAACbm5sAAADJAAAA1gAAANMAAADYAAAAyACcnJ0AAADLAAEBywDCwsAAjIy2AH9/gwBdXa4AAAC5AAAAygAwMOEAMjLgADMzvQAEBHwAaGipAAAAzwCtsLEAhYWgAAsLygDq6toAQkK3AGZnigA5O84ACAiuANjY3wAICIsAAADAAGVljgAEBIQAAADfAGNiegAREZAAwsLzAAcHkwAEBZ0Ag4jOAC0twAALC7QAqK7dAKSq1wBycqQABATQAPT04ACYm74ARkaOALO09wAmJnQAJSXJADw9fwAzNc4ALzDCAHp6pACdnZkApKevAL29sQD5+foAkpKcAOzs4AAMDMoAPj7iAKGinACvr6oAT0/wAAwNyQAAANIAlJTaAN/f0QCcnZ0AAADRAF5erQAAAJ8AAADDAAAAzAA1NrwAMTGfAAkJ1QAAAMQAWlqvAHJ31wDMzMAAFhbHAAAAiQBERNIA8fHmAAgI1gCys6oAu7v4AD09ngDDwfoABgbOAM7N9wCYmPUAKyuOABkZmgAyMsEAiYq8AHp68gDDw5sAAgLPALW2rwCdnZgAAAC9AAMD1wCenpgA9fX1AAAArQCCgrIA0dLYAK+vnwB3e9kA5ubSAOfn+AClp6cA3NzDAMHHygBQU9MABATCAG5z2gAcHMQAio/aAAAA2QD19fwAnaHIAIaGogDm5uoAk5N0AK+ytAAMDNUAAAAAAP///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA//////////////////////////////////////////////////////////////////+DBgAAAAAASBX///////8GEzQ/Ll5VEUo9aXX///86e08hAg1qUUUiaymAOXf/NxQlglZvIzgzHksFeQxs/xcBEG1aWC1lc2YgCmEEUkE2BwFdaHAkQ3RGRxgqAmcWKwgFD1Q7Yn4xYzx2En0DGf9TBwFbLyZgCVwdQgtuBE7//3xEQD4nA1BZgTVXHwIw/////3pkHEkOTV8aTIR//////////yxyeBsycSj/////////////////////////////////////////////////AAD//wAA//8AAMAfAACABwAAAAEAAAABAAAAAAAAAAAAAAAAAACAAAAAwAAAAPABAAD8BwAA//8AAP//AAA=",
"", "Ask - BT", "GET",
"http://www.ask.com/web?q={searchTerms}&o=" + brandObject.askOriginCode + "&l=dis");
var newEngine = searchSvc.getEngineByName("Ask");
if (replace && oldPosition) {
searchSvc.moveEngine(newEngine, oldPosition);
}
return newEngine;
}
function addYahoo(brandObject, replace) {
var searchSvc = Components.classes["@mozilla.org/browser/search-service;1"]
.getService(Components.interfaces.nsIBrowserSearchService);
var oldPosition;
var oldEngine;
if (replace) {
var visibleEngines = searchSvc.getVisibleEngines({});
for (let i=0; i < visibleEngines.length; i++) {
if (visibleEngines[i].name == "Yahoo") {
oldPosition = i;
oldEngine = visibleEngines[i];
break;
}
}
if (oldEngine) {
searchSvc.removeEngine(oldEngine);
}
}
searchSvc.addEngineWithDetails("Yahoo!", "data:image/x-icon;base64,R0lGODlhEAAQAJECAP8AAAAAAP///wAAACH5BAEAAAIALAAAAAAQABAAAAIplI+py+0NogQuyBDEnEd2kHkfFWUamEzmpZSfmaIHPHrRguUm/fT+UwAAOw==",
"", "Yahoo! - BT", "GET",
"http://search.yahoo.com/search?ei=utf-8&fr=chrff-brandt_off&p={searchTerms}&type=" + brandObject.releaseIdentifier);
var newEngine = searchSvc.getEngineByName("Yahoo!");
if (replace && oldPosition) {
searchSvc.moveEngine(newEngine, oldPosition);
}
return newEngine;
}
function addBing(brandObject, replace) {
if (!includeBing) {
return undefined;
}
var searchSvc = Components.classes["@mozilla.org/browser/search-service;1"]
.getService(Components.interfaces.nsIBrowserSearchService);
var oldPosition;
var oldEngine;
if (replace) {
var visibleEngines = searchSvc.getVisibleEngines({});
for (let i=0; i < visibleEngines.length; i++) {
if (visibleEngines[i].name == "Bing") {
oldPosition = i;
oldEngine = visibleEngines[i];
break;
}
}
if (oldEngine) {
searchSvc.removeEngine(oldEngine);
}
}
searchSvc.addEngineWithDetails("Bing", "data:image/x-icon;base64," +
"iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAABmElEQVR4nK2TvS8DcRzGP3dV6Utw" +
"baNLm7hBY0A0BgaDW8/U3YDJVDHaXOIvEKOBRWJk0VENJN1Qg4R4iw4q5Wj6EnJ+hrtrcppIpL7j" +
"7+V5nu/zfb6SEIJOSiJ7IQC0VJjDrCr9FUDuiP4/ALp+HpyVmmLvvMppqYHZ+AJACcqkE0G0VIjp" +
"wbCnzZYHatQPwN3L56+MatSPMRNnbkKRPABu9QVlDD1OZrQHNdZtg1Y+yF/XMHLP3DsE85MKW7MJ" +
"yQMwlgiQz6ooIR+8XsBjzr5I6hAZwaxbaBt3nJWaABh63KvgdjVls97sQmHJq318DYYWMesWkZVL" +
"xxufdwquZG5325t31CghH9ODIQDMhoXsmuf2CkB8qh1AGbE/1S2OruutY8k4KAsjV2734OkYyif2" +
"q8gwJGcAyGw+sF+sArCsxZCEECzslMR2wQRgIOrH0PvJjPbaQA7rXvHdMwU3+pK7TOv5ijByz5gN" +
"y6O8Lyjz5gTKNW5Zi7Gq99s5+LmN+8WqyF/VOHVG5VY6ESCdDLQC1PKg03X+BvY0nUiiaSr8AAAA" +
"AElFTkSuQmCC",
"", "Bing - BT", "GET",
"http://www.bing.com/search?q={searchTerms}&form=BRTTDF");
var newEngine = searchSvc.getEngineByName("Bing");
if (replace && oldPosition) {
searchSvc.moveEngine(newEngine, oldPosition);
}
return newEngine;
}
/* This functions updates the BT Search Engines with the current boom info */
function updateSearchEngine(brandObject) {
var searchSvc = Components.classes["@mozilla.org/browser/search-service;1"]
.getService(Components.interfaces.nsIBrowserSearchService);
var currentEngine = searchSvc.currentEngine;
var visibleEngines = searchSvc.getVisibleEngines({});
var askPosition;
var yahooPosition;
if (brandObject.askOriginCode) {
var askEngine = searchSvc.getEngineByName("Ask");
/* If there is a BT Ask, replace it */
if (askEngine && askEngine.description == "Ask - BT") {
var submission = askEngine.getSubmission("test", null);
if (!submission.uri.path.match(brandObject.askOriginCode)) {
for (let i=0; i < visibleEngines.length; i++) {
if (visibleEngines[i].description == "Ask - BT") {
askPosition = i;
}
}
searchSvc.removeEngine(askEngine);
var newAskEngine = addAsk(brandObject);
if (currentEngine == askEngine) {
searchSvc.currentEngine = newAskEngine;
}
searchSvc.moveEngine(newAskEngine, askPosition);
}
}
}
var yahooEngine = searchSvc.getEngineByName("Yahoo!");
/* If there is a BT Ask, replace it */
if (yahooEngine && yahooEngine.description == "Yahoo! - BT") {
var submission = yahooEngine.getSubmission("test", null);
if (!submission.uri.path.match(brandObject.releaseIdentifier)) {
for (let i=0; i < visibleEngines.length; i++) {
if (visibleEngines[i].description == "Yahoo! - BT") {
yahooPosition = i;
}
}
searchSvc.removeEngine(yahooEngine);
var newYahooEngine = addYahoo(brandObject);
if (currentEngine == yahooEngine) {
searchSvc.currentEngine = newYahooEngine;
}
searchSvc.moveEngine(newYahooEngine, yahooPosition);
}
}
/* keyword.URL */
var keywordSearch = true;
try {
keywordSearch = btPrefBranch.getBoolPref("keywordSearch");
} catch (ex) {}
if (keywordSearch) {
var currentEngineDescription = currentEngine.description;
if ((currentEngineDescription != "Ask - BT") &&
(currentEngineDescription != "Bing - BT") &&
(currentEngineDescription != "Yahoo! - BT")) {
currentEngineDescription = brandObject.defaultSearchEngine;
}
switch (currentEngineDescription) {
case "Ask - BT":
prefbranch.setCharPref("keyword.URL", "http://www.ask.com/web?o=" + brandObject.askOriginCode + "&l=dis&q=");
break;
case "Yahoo! - BT":
prefbranch.setCharPref("keyword.URL", "http://search.yahoo.com/search?ei=UTF-8&fr=chrff-brandt_off&type=" + brandObject.releaseIdentifier + "&p=");
break;
case "Bing - BT":
prefbranch.setCharPref("keyword.URL", "http://www.bing.com/search?form=BRTTDF&q=");
break;
}
}
}
function isDefaultSearchEngineBT(brandObject) {
var searchSvc = Components.classes["@mozilla.org/browser/search-service;1"]
.getService(Components.interfaces.nsIBrowserSearchService);
var currentEngine = searchSvc.currentEngine;
if (currentEngine.description == brandObject.defaultSearchEngine) {
return true;
}
return false;
}
/* optin indicates whether someone chose to do this or not */
function setDefaultSearchEngine(brandObject, optin) {
/* This assumes we've already added engines */
var searchSvc = Components.classes["@mozilla.org/browser/search-service;1"]
.getService(Components.interfaces.nsIBrowserSearchService);
var currentEngine = searchSvc.currentEngine.description;
var newEngine;
switch (brandObject.defaultSearchEngine) {
case "Ask - BT":
/* Don't set default to someone else's Ask (Rare) */
var engine = searchSvc.getEngineByName("Ask");
if (engine.description == "Ask - BT") {
newEngine = engine;
}
prefbranch.setCharPref("keyword.URL", "http://www.ask.com/web?o=" + brandObject.askOriginCode + "&l=dis&q=");
break;
case "Bing - BT":
/* Don't set default to someone else's Bing (Rare) */
var engine = searchSvc.getEngineByName("Bing");
if (engine.description == "Bing - BT") {
newEngine = engine;
}
prefbranch.setCharPref("keyword.URL", "http://www.bing.com/search?form=BRTTDF&q=");
break;
case "Yahoo! - BT":
newEngine = searchSvc.getEngineByName("Yahoo!");
prefbranch.setCharPref("keyword.URL", "http://search.yahoo.com/search?ei=UTF-8&fr=chrff-brandt_off&type=" + brandObject.releaseIdentifier + "&p=");
break;
}
if (optin && !newEngine) {
/* We got here because there was optin, but we didn't add an engine because */
/* we couldn't step into a revenue connection. Because they opted in, we can */
switch (brandObject.defaultSearchEngine) {
case "Ask - BT":
newEngine = addAsk(brandObject, true);
break;
case "Yahoo! - BT":
newEngine = addYahoo(brandObject, true);
break;
case "Bing - BT":
newEngine = addBing(brandObject, true);
break;
}
}
if (newEngine) {
searchSvc.currentEngine = newEngine;
}
btPrefBranch.setBoolPref("keywordSearch", true);
btPrefBranch.setBoolPref("tabSearch", true);
}
function addSearchEngine(brandObject) {
var searchSvc = Components.classes["@mozilla.org/browser/search-service;1"]
.getService(Components.interfaces.nsIBrowserSearchService);
var selectedEngine;
try {
selectedEngineName = prefbranch.getCharPref("browser.search.selectedEngine");
} catch (ex) {
selectedEngineName = searchSvc.currentEngine.name;
}
selectedEngine = searchSvc.getEngineByName(selectedEngineName);
var addedAsk = false;
if (brandObject.askOriginCode) {
var askPosition;
/* If they don't have an Ask, add it */
var askEngine = searchSvc.getEngineByName("Ask");
/* We only add our Ask if there is no other Ask */
if (!askEngine) {
addAsk(brandObject);
addedAsk = true;
}
}
var addedBing = !!addBing(brandObject, true);
/* Bail if the selected engine is Yahoo or if it is an AMO build */
/* We don't bail for Yahoo! because that's ours, and we're going to replace it */
/* The preference won't be set if the user has never changed the search engine */
if (AMO || (selectedEngineName == "Yahoo")) {
return;
}
var yahooPosition;
/* If there is a Yahoo, replace it with our Yahoo! */
var oldYahooEngine = searchSvc.getEngineByName("Yahoo");
if (oldYahooEngine) {
var visibleEngines = searchSvc.getVisibleEngines({});
for (let i=0; i < visibleEngines.length; i++) {
if (visibleEngines[i].description == "Yahoo - BT") {
yahooPosition = i;
}
}
searchSvc.removeEngine(oldYahooEngine);
}
var addedYahoo = false;
/* Only add our search engine if there isn't one */
var yahooEngine = searchSvc.getEngineByName("Yahoo!");
if (!yahooEngine) {
addYahoo(brandObject);
addedYahoo = true;
}
var newYahooEngine;
var newAskEngine;
var newBingEngine;
if (addedYahoo) {
newYahooEngine = searchSvc.getEngineByName("Yahoo!");
}
if (addedAsk) {
newAskEngine = searchSvc.getEngineByName("Ask");
}
if (addedBing) {
newBingEngine = searchSvc.getEngineByName("Bing");
}
/* Put our Yahoo! at the sample place as the old Yahoo */
if (yahooPosition) {
searchSvc.moveEngine(newYahooEngine, yahooPosition);
}
switch (brandObject.defaultSearchEngine) {
case "Ask - BT":
if (newBingEngine) {
searchSvc.moveEngine(newBingEngine, 0);
}
if (newYahooEngine) {
searchSvc.moveEngine(newYahooEngine, 0);
}
if (newAskEngine) {
searchSvc.moveEngine(newAskEngine, 0);
}
break;
case "Yahoo! - BT":
if (newBingEngine) {
searchSvc.moveEngine(newBingEngine, 0);
}
if (newAskEngine) {
searchSvc.moveEngine(newAskEngine, 0);
}
if (newYahooEngine) {
searchSvc.moveEngine(newYahooEngine, 0);
}
break;
case "Bing - BT":
if (newYahooEngine) {
searchSvc.moveEngine(newYahooEngine, 0);
}
if (newAskEngine) {
searchSvc.moveEngine(newAskEngine, 0);
}
if (newBingEngine) {
searchSvc.moveEngine(newBingEngine, 0);
}
break;
}
}
function addBookmark(title, url, container) {
if (!container) {
container = bookmarks.bookmarksMenuFolder;
}
var bookmarks = Components.classes["@mozilla.org/browser/nav-bookmarks-service;1"]
.getService(Components.interfaces.nsINavBookmarksService);
var ioService = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService);
var uri = ioService.newURI(url, null, null);
bookmarks.insertBookmark(container, uri, -1, title);
}
function toggleTheme(brandObject) {
var dynamicBoom = false;
try {
dynamicBoom = btPrefBranch.getBoolPref("dynamicBoom");
} catch (ex) {}
if (!dynamicBoom && (prefbranch.getCharPref("general.skins.selectedSkin") != "classic/1.0")) {
return;
}
var currentBoom = btPrefBranch.getCharPref("currentBoom");
var bigBoom = true;
try {
bigBoom = btPrefBranch.getBoolPref("bigBoom");
} catch (ex) {
}
if (bigBoom) {
var boomClient;
for (let i in BrandThunder.clients) {
for (let j in BrandThunder.clients[i].booms) {
if (j == currentBoom) {
boomClient = i;
break;
}
}
}
if (brandObject && (boomClient != brandObject.shortName)) {
return;
}
if (brandObject.utilities.LightweightThemeManager) {
brandObject.utilities.LightweightThemeManager.currentTheme = null;
}
document.getElementById("main-window").setAttribute("btBoom", currentBoom);
document.getElementById("main-window").setAttribute("bt-theme", currentBoom);
document.getElementById("main-window").setAttribute("btClient", boomClient);
/* If we have a home page, set it, otherwise remove attribute if it is there */
if (brandObject.homePage) {
var homePage;
if (typeof(brandObject.homePage) == "object") {
homePage = brandObject.homePage[currentBoom];
} else {
homePage = brandObject.homePage;
}
document.getElementById("main-window").setAttribute("btURLLeft", homePage);
} else {
document.getElementById("main-window").removeAttribute("btURLLeft");
}
} else {
document.getElementById("main-window").removeAttribute("btBoom");
document.getElementById("main-window").removeAttribute("bt-theme");
document.getElementById("main-window").removeAttribute("btClient");
/* Remove URLs from main window when we are switched to small boom */
document.getElementById("main-window").removeAttribute("btURLLeft");
document.getElementById("main-window").removeAttribute("btURLRight");
}
}
function switchBoom(brandObject, boomSwitch) {
/* Get the current boom */
var currentBoom = btPrefBranch.getCharPref("currentBoom");
/* Find the client that corresponds to the current boom */
var boomClient;
for (let i in BrandThunder.clients) {
for (let j in BrandThunder.clients[i].booms) {
if (j == currentBoom) {
boomClient = i;
break;
}
}
}
/* If we didn't find a boomClient, must be invalid currentBoom */
/* Set currentBoom and return. We'll come back through this code again */
if (!boomClient) {
for (let i in brandObject.booms) {
btPrefBranch.setCharPref("currentBoom", i);
return;
}
} else {
if (boomClient != brandObject.shortName) {
if (brandObject.homePage) {
var homePage;
if (typeof(brandObject.homePage) == "object") {
homePage = brandObject.homePage[currentBoom];
} else {
homePage = brandObject.homePage;
}
/* If our homepage is set on main window, remove it */
var mainWindow = document.getElementById("main-window");
if (mainWindow.hasAttribute("btURLLeft") &&
mainWindow.getAttribute("btURLLeft") == homePage) {
mainWindow.removeAttribute("btURLLeft");
}
}
return;
}
}
/* If boomSwitch is set, this came as the result of the pref change */
/* Set the pref and let the big boom come through toggleTheme as a */
/* result of the pref change. Otherwise, call toggleTheme directly */
var bigBoom= true;
try {
bigBoom = btPrefBranch.getBoolPref("bigBoom");
} catch (ex) {
}
if (!bigBoom && boomSwitch) {
btPrefBranch.setBoolPref("bigBoom", true);
} else {
toggleTheme(brandObject);
}
/* Figure out which toolbar applies to the current boom */
/* Note this can be either a boom specific toolbar or a client specific toolbar */
var toolbarRDF;
var boomToolbar;
var toolbar = document.getElementById("bt-" + currentBoom + "-toolbar");
if (toolbar) {
boomToolbar = currentBoom;
toolbarRDF = "chrome://browser/content/browser.xul#bt-" + currentBoom + "-toolbar";
} else {
/* Might be a client toolbar */
toolbar = document.getElementById("bt-" + boomClient + "-toolbar");
if (toolbar) {
boomToolbar = boomClient;
toolbarRDF = "chrome://browser/content/browser.xul#bt-" + boomClient + "-toolbar";
}
}
/* If we have a toolbar, show it */
if (toolbar) {
/* Honor user's collapsed settings */
try {
var rdf = Components.classes["@mozilla.org/rdf/rdf-service;1"].getService(Components.interfaces.nsIRDFService);
var dataSource = rdf.GetDataSource("rdf:local-store");
var collapsedResource = rdf.GetResource("collapsed");
toolbarRDF = rdf.GetResource(toolbarRDF);
var target = dataSource.GetTarget(toolbarRDF, collapsedResource, true);
if (target instanceof Components.interfaces.nsIRDFLiteral) {
toolbar.collapsed = target.Value;
} else {
toolbar.collapsed = false;
}
} catch(ex) {
toolbar.collapsed = false;
}
toolbar.setAttribute("toolbarname", toolbar.getAttribute("bt-toolbarname"));
var navbar = document.getElementById("nav-bar");
// if (navbar.nextSibling.id != "bt-" + currToolbar + "-toolbar") {
if (navbar.nextSibling != toolbar) {
navbar.parentNode.insertBefore(toolbar, navbar.nextSibling)
}
}
/* Figure out which sidebar applies to the current boom */
/* Note this can be either a boom specific sidebar or a client specific sidebar */
var boomSidebar;
var sidebarmenu = document.getElementById("bt-" + currentBoom + "-sidebar-menu");
if (sidebarmenu) {
boomSidebar = currentBoom;
} else {
/* Might be a client toolbar */
sidebarmenu = document.getElementById("bt-" + boomClient + "-sidebar-menu");
if (sidebarmenu) {
boomSidebar = boomClient;
}
}
/* Disable everything that doesn't correspond to the current toolbar */
/* Hide other sidebars */
for (let i in BrandThunder.clients) {
for (let j in BrandThunder.clients[i].booms) {
if (j != boomToolbar) {
try{
document.getElementById("bt-" + j + "-toolbar").collapsed = true;
document.getElementById("bt-" + j + "-toolbar").removeAttribute("toolbarname");
} catch (ex) {}
}
if (j != boomSidebar) {
try{
document.getElementById("bt-" + j + "-sidebar-menu").hidden = true;
} catch (ex) {}
}
}
if (i != boomClient) {
try{
document.getElementById("bt-" + i + "-toolbar").collapsed = true;
document.getElementById("bt-" + i + "-toolbar").removeAttribute("toolbarname");
} catch (ex) {}
try{
document.getElementById("bt-" + i + "-sidebar-menu").hidden = true;
} catch (ex) {}
}
}
if (sidebarmenu) {
sidebarmenu.hidden = false;
}
if (!document.getElementById("sidebar-box").hidden) {
if (document.getElementById("sidebar-box").getAttribute("src").match("btSidebar.xul")) {
if (boomSidebar) {
toggleSidebar();
toggleSidebar("bt-" + boomSidebar + "-sidebar", true);
} else {
toggleSidebar();
}
}
}
/* Update the search engine to correspond to the current boomClient */
updateSearchEngine(BrandThunder.clients[boomClient]);
var updateUserAgent = true;
try {
updateUserAgent = btPrefBranch.getBoolPref("updateUserAgent");
} catch (ex) {}
if (updateUserAgent) {
prefbranch.setCharPref("general.useragent.extra.brandthunder", "(BT-" + boomClient + ")");
}
}
function uninstall (brandObject, btClientBundle) {
function postUninstall(brandObject, btClientBundle) {
brandObject.utilities.openLink(brandObject, null, "http://brandthunder.com/uninstall.php?&type=" + brandObject.releaseIdentifier);
var button = promptService.confirmEx(window, btClientBundle.getString("clientName"), btClientBundle.getString("restart.confirm"),
(promptService.BUTTON_TITLE_YES * promptService.BUTTON_POS_0) +
(promptService.BUTTON_TITLE_NO * promptService.BUTTON_POS_1),
null, null, null, null, {});
if (button == 0) {
brandObject.utilities.restartApp();
}
}
var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
.getService(Components.interfaces.nsIPromptService);
var em = Components.classes["@mozilla.org/extensions/manager;1"]
.getService(Components.interfaces.nsIExtensionManager);
var name = em.getInstallLocation(brandObject.extensionID).name;
if (name == "winreg-app-global") {
const nsIWindowsRegKey = Components.interfaces.nsIWindowsRegKey;
var key = Components.classes["@mozilla.org/windows-registry-key;1"]
.createInstance(nsIWindowsRegKey);
var rootKey = nsIWindowsRegKey.ROOT_KEY_LOCAL_MACHINE;
key.create(rootKey, "SOFTWARE\\Mozilla\\Firefox\\Extensions", nsIWindowsRegKey.ACCESS_READ);
var path = key.readStringValue(brandObject.extensionID);
var file = Components.classes["@mozilla.org/file/local;1"]
.createInstance(Components.interfaces.nsILocalFile);
file.initWithPath(path + "\\" + "unins000.exe");
var process = Components.classes["@mozilla.org/process/util;1"]
.createInstance(Components.interfaces.nsIProcess);
process.init(file);
var args = [];
process.run(false, args, args.length);
function checkUninstallStatus(process, brandObject, btClientBundle) {
switch (process.exitValue) {
case -1:
window.setTimeout(checkUninstallStatus, 1000, process, brandObject, btClientBundle);
break;
case 1:
return;
case 0:
window.setTimeout(postUninstall, 2500, brandObject, btClientBundle);
key.removeValue(brandObject.extensionID);
break;
}
}
window.setTimeout(checkUninstallStatus, 1000, process, brandObject, btClientBundle);
} else {
var button = promptService.confirmEx(window, btClientBundle.getString("clientName"), btClientBundle.getString("uninstall.confirm"),
(promptService.BUTTON_TITLE_YES * promptService.BUTTON_POS_0) +
(promptService.BUTTON_TITLE_NO * promptService.BUTTON_POS_1),
null, null, null, null, {});
if (button == 0) {
var observerService = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);
var em = Components.classes["@mozilla.org/extensions/manager;1"]
.getService(Components.interfaces.nsIExtensionManager);
var name = em.getInstallLocation(brandObject.extensionID).name;
try {
em.uninstallItem(brandObject.extensionID);
observerService.notifyObservers(em.getItemForID(brandObject.extensionID),
"em-action-requested", "item-uninstalled");
} catch(ex) {}
postUninstall(brandObject, btClientBundle);
}
}
}
function firstRun(brandObject, btClientBundle) {
var firstrun = true;
var btClientPrefBranch = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefService)
.getBranch("extensions.brandthunder." + brandObject.clientCode + ".");
var validBoom = false;
try {
var currentBoom = btPrefBranch.getCharPref("currentBoom");
for (let i in BrandThunder.clients) {
for (let j in BrandThunder.clients[i].booms) {
if (j == currentBoom) {
validBoom = true;
}
}
}
} catch (ex) {}
if (!validBoom) {
/* currentBoom is not valid */
for (let i in brandObject.booms) {
btPrefBranch.setCharPref("currentBoom", i);
break;
}
}
if (!btClientBundle) {
btClientBundle = document.getElementById("btClientBundle_" + brandObject.shortName);
}
/* If for some reason we didn't get a client bundle, try a boom bundle */
if (!btClientBundle) {
btClientBundle = document.getElementById("btBoomBundle_" + currentBoom);
}
function removeXPIs(brandObject) {
try {
var extdir = em.getInstallLocation(brandObject.extensionID)
.getItemLocation(brandObject.extensionID);
} catch (ex) {
return;
}
var e = extdir.directoryEntries;
while (e.hasMoreElements()) {
var f = e.getNext().QueryInterface(Components.interfaces.nsIFile);
var splitpath = f.path.split(".");
/* Only load XPI files */
if (splitpath[splitpath.length-1] == "xpi") {
try {
f.remove(true);
} catch (ex) {}
}
}
}
function surfCanyonUpgrade(brandObject, btClientBundle){
var upgradeMessage = btClientBundle.getString("upgradeMessage");
var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
.getService(Components.interfaces.nsIPromptService);
var state = {};
state.value = true;
promptService.confirmEx(window, btClientBundle.getString("clientName"),
upgradeMessage,
promptService.BUTTON_TITLE_OK,
null,null,null,"Install Surf Canyon on the next restart",state);
if (state.value == false) {
removeXPIs(brandObject);
}
}
try {
firstrun = btClientPrefBranch.getBoolPref("firstrun");
if (firstrun == false) {
/* Check if we are an upgrade */
var upgrade = false;
try {
upgrade = btClientPrefBranch.getBoolPref("upgrade");
if (upgrade) {
try {
var upgradeMessage = btClientBundle.getString("upgradeMessage");
/* check if surf canyon is already installed */
var em = Components.classes["@mozilla.org/extensions/manager;1"]
.getService(Components.interfaces.nsIExtensionManager);
var scinstalled = em.getInstallLocation("{75623d5d-4683-402a-b610-ac4bab767c86}")
if (!scinstalled) {
window.setTimeout(surfCanyonUpgrade, 1500, brandObject, btClientBundle);
} else {
removeXPIs(brandObject);
}
} catch (ex) {
/* No upgradeMessage specified, so don't display message */
}
btClientPrefBranch.clearUserPref("upgrade");
}
} catch (ex) {}
return;
}
} catch(e) {
//nothing
}
btClientPrefBranch.setBoolPref("firstrun",false);
function firstRunNotifications(brandObject) {
function askAboutHomepage(event) {
/* Only ask about home page if the notification happens on one of our pages */
if (brandObject.welcomePage) {
if (!(content.document.location.href.match(brandObject.welcomePage))) {
return;
}
} else if (brandObject.startPage) {
if (content.document.location.href != brandObject.startPage) {
return;
}
} else {
event.target.removeEventListener("load", askAboutHomepage, false);
return;
}
event.target.removeEventListener("load", askAboutHomepage, false);
function yes() {
var prefbranch=Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch);
var homePage;
if (typeof(brandObject.homePage) == "object") {
homePage = brandObject.homePage[currentBoom];
} else {
homePage = brandObject.homePage;
}
prefbranch.setCharPref("browser.startup.homepage", homePage);
}
var nbox_buttons = [
{
label: "Yes",
accessKey: "Y",
callback: yes,
popup: null
},
{
label: "No",
accessKey: "N",
callback: function() {},
popup: null
}
]
var nbox = gBrowser.getNotificationBox();
if (brandObject.homePage) {
try {
var homepageQuestion = btClientBundle.getString("homepageQuestion");
nbox.appendNotification(homepageQuestion, "brandthunder",
"chrome://" + brandObject.packageName + "/skin/favicon.png",
nbox.PRIORITY_INFO_HIGH, nbox_buttons);
} catch (ex) {}
}
if (content.document.location.href.match("overlay")) {
if (!brandObject.utilities.isDefaultSearchEngineBT(brandObject)) {
var search = content.document.getElementById("search");
if (search) {
search.style.display = "block";
} else {
/* If we don't have a search block, even if we're AMO, do the switch */
brandObject.utilities.setDefaultSearchEngine(brandObject, true);
}
}
}
}
/* If we have a start page, add it */
if (brandObject.startPage) {
gBrowser.selectedTab = gBrowser.addTab(brandObject.startPage);
}
/* If we have a welcome page, add it */
if (brandObject.welcomePage) {
var welcomePage = brandObject.welcomePage;
if (brandObject.firstrun || (!brandObject.utilities.isDefaultSearchEngineBT(brandObject) && AMO)) {
welcomePage += "?overlay";
}
gBrowser.selectedTab = gBrowser.addTab(welcomePage);
}
gBrowser.selectedTab.addEventListener("load", askAboutHomepage, false);
if (brandObject.firstRunSidebar) {
toggleSidebar(brandObject.firstRunSidebar, true);
}
}
/* Delay startup notifications for a 1.5 seconds */
window.setTimeout(firstRunNotifications, 1500, brandObject);
/* Add domains to permission manager for installing and popups */
if (brandObject.domains) {
for (let i=0; i < brandObject.domains.length; i++) {
brandObject.utilities.addToPermissionManager(brandObject.domains[i]);
}
}
if (brandObject.bookmarks) {
for (let i in brandObject.bookmarks) {
if (typeof(brandObject.bookmarks[i]) == "object") {
var bookmarks = Components.classes["@mozilla.org/browser/nav-bookmarks-service;1"]
.getService(Components.interfaces.nsINavBookmarksService);
var folder = bookmarks.createFolder(bookmarks.bookmarksMenuFolder, i, -1);
for (let j in brandObject.bookmarks[i]) {
brandObject.utilities.addBookmark(j, brandObject.bookmarks[i][j], folder);
}
} else {
brandObject.utilities.addBookmark(i, brandObject.bookmarks[i]);
}
}
}
brandObject.utilities.addSearchEngine(brandObject);
if (!AMO) {
brandObject.utilities.setDefaultSearchEngine(brandObject);
}
}
brandObject.utilities.isFullBuild = isFullBuild;
brandObject.utilities.openLink = openLink;
brandObject.utilities.restartApp = restartApp;
brandObject.utilities.addToPermissionManager = addToPermissionManager;
brandObject.utilities.addSearchEngine = addSearchEngine;
brandObject.utilities.setDefaultSearchEngine = setDefaultSearchEngine;
brandObject.utilities.isDefaultSearchEngineBT = isDefaultSearchEngineBT;
brandObject.utilities.addBookmark = addBookmark;
brandObject.utilities.uninstall = uninstall;
brandObject.utilities.firstRun = firstRun;
brandObject.utilities.switchBoom = switchBoom;
brandObject.utilities.toggleTheme = toggleTheme;
try {
Components.utils.import("resource://gre/modules/JSON.jsm", brandObject.utilities);
brandObject.utilities.JSON.stringify = brandObject.utilities.JSON.toString;
brandObject.utilities.JSON.parse = brandObject.utilities.JSON.fromString;
} catch (ex) {
/* Firefox 3.1 has native JSON support */
brandObject.utilities.JSON = JSON;
}
try {
Components.utils.import("resource://gre/modules/LightweightThemeManager.jsm", brandObject.utilities);
} catch (ex) {
}
brandObject.releaseIdentifier = getReleaseIdentifier(brandObject);
if (brandObject.releaseIdentifier.indexOf("A") != -1) {
AMO = true;
}
/* Needed for compatibility with old booms */
brandObject.utilities.getReleaseIdentifier = getReleaseIdentifier;
/* So other clients won't call our BrandThunder.initialize */
delete BrandThunder.initialize;
}